package com.guiji.file.controller;

import java.util.List;
import java.util.Arrays;

import com.guiji.file.bo.CmsBucketAddBo;
import com.guiji.file.bo.CmsBucketEditBo;
import com.guiji.file.bo.CmsBucketQueryBo;
import com.guiji.file.service.ICmsBucketService;
import com.guiji.file.vo.CmsBucketVo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.guiji.common.annotation.RepeatSubmit;
import com.guiji.common.annotation.Log;
import com.guiji.common.core.controller.BaseController;
import com.guiji.common.core.domain.AjaxResult;
import com.guiji.common.enums.BusinessType;
import com.guiji.common.utils.poi.ExcelUtil;
import com.guiji.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2021-07-26
 */
@Api(value = "桶管理", tags = {"桶管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/bucket")
public class CmsBucketController extends BaseController {

	private final ICmsBucketService iCmsBucketService;

	/**
	 * 查询【请填写功能名称】列表
	 */
	@ApiOperation("查询【请填写功能名称】列表")
	@PreAuthorize("@ss.hasPermi('system:bucket:list')")
	@GetMapping("/list")
	public TableDataInfo<CmsBucketVo> list(@Validated CmsBucketQueryBo bo) {
		return iCmsBucketService.queryPageList(bo);
	}

	/**
	 * 导出【请填写功能名称】列表
	 */
	@ApiOperation("导出【请填写功能名称】列表")
	@PreAuthorize("@ss.hasPermi('system:bucket:export')")
	@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult<CmsBucketVo> export(@Validated CmsBucketQueryBo bo) {
		List<CmsBucketVo> list = iCmsBucketService.queryList(bo);
		ExcelUtil<CmsBucketVo> util = new ExcelUtil<CmsBucketVo>(CmsBucketVo.class);
		return util.exportExcel(list, "【请填写功能名称】");
	}

	/**
	 * 获取【请填写功能名称】详细信息
	 */
	@ApiOperation("获取【请填写功能名称】详细信息")
	@PreAuthorize("@ss.hasPermi('system:bucket:query')")
	@GetMapping("/{bucketId}")
	public AjaxResult<CmsBucketVo> getInfo(@NotNull(message = "主键不能为空")
										   @PathVariable("bucketId") Long bucketId) {
		return AjaxResult.success(iCmsBucketService.queryById(bucketId));
	}

	/**
	 * 新增【请填写功能名称】
	 */
	@ApiOperation("新增【请填写功能名称】")
	@PreAuthorize("@ss.hasPermi('system:bucket:add')")
	@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
	@RepeatSubmit
	@PostMapping()
	public AjaxResult<Void> add(@Validated @RequestBody CmsBucketAddBo bo) {
		return toAjax(iCmsBucketService.insertByAddBo(bo) ? 1 : 0);
	}

	/**
	 * 修改【请填写功能名称】
	 */
	@ApiOperation("修改【请填写功能名称】")
	@PreAuthorize("@ss.hasPermi('system:bucket:edit')")
	@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping()
	public AjaxResult<Void> edit(@Validated @RequestBody CmsBucketEditBo bo) {
		return toAjax(iCmsBucketService.updateByEditBo(bo) ? 1 : 0);
	}

	/**
	 * 删除【请填写功能名称】
	 */
	@ApiOperation("删除【请填写功能名称】")
	@PreAuthorize("@ss.hasPermi('system:bucket:remove')")
	@Log(title = "【请填写功能名称】" , businessType = BusinessType.DELETE)
	@DeleteMapping("/{bucketIds}")
	public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
								   @PathVariable Long[] bucketIds) {
		return toAjax(iCmsBucketService.deleteWithValidByIds(Arrays.asList(bucketIds), true) ? 1 : 0);
	}
}
